import Vue from 'vue'
import VueRouter from 'vue-router'

const originalPush = VueRouter.prototype.push;

// 重写push函数，防止控制台出现路由跳转错误
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(error => error);
};

Vue.use(VueRouter);

/**
 * @description: 常规路由
 * @return {*}
 */
export const constantRoutes = [
  {
    path: '/',
    name: 'home',
    redirect: '/dashboard',
    component: () => import('../views/Home.vue'),
    children: [{
      path: '/dashboard',
      name: 'dashboard',
      component: () => import('../views/dashboard.vue')
    }]
  },
  {
    path: '/Login',
    name: 'login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/',
    name: 'home1',
    component: () => import('../views/Home.vue'),
    children: [{
      path: '/easyflow',
      name: 'easyflow',
      component: () => import('../views/easyflow.vue')
    },
    {
      path: '/sys/dic/index',
      name: 'sys_dic_index',
      component: () => import('../views/Sys/index')
    }]
  }
]

/**
 * @description: 业务路由
 * @return {*}
 */
export const asyncRoutes = []

let routes = constantRoutes.concat(asyncRoutes);

const router = new VueRouter({
  scrollBehavior: () => ({ y: 0 }),
  routes: routes
})

export default router
